<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/5/28
 * Time: 17:56
 */

namespace Biz\service;

use Biz\module\Packages\CustomerService\SmallEnergy as csSmallEnergy;
use Doraemon\tools\Log as tLog;
/**
 * @deprecated
 */
class SmallEnergy
{
    public static function getSmallEnergyId($uid)
    {

        try{

            $smallEnergyUserInfo['id'] = csSmallEnergy::getSmallEnergyId($uid);

            return $smallEnergyUserInfo;

        } catch (\Exception $e) {

            tLog::smallenergy_user_warning('获取id失败', [
                'uid'       => $uid,
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }

    }

    public static function getMerchantInfo($groupIds)
    {

        try{

            $merchantInfo = csSmallEnergy::getMerchantInfo($groupIds);

            $data = array(
                'list' => $merchantInfo ? : []
            );

            return $data;

        } catch (\Exception $e) {

            tLog::smallenergy_shop_warning('获取商家信息失败', [
                'group_ids'       => $groupIds,
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }

    }

    public static function getSmallEnergyList($where = [])
    {

        try{

            // 查询列表
            $smallEnergyList = csSmallEnergy::getSmallEnergyList($where);

            $array = [
                'list' => $smallEnergyList,
                'count' => count($smallEnergyList),
            ];

            return $array;

        } catch (\Exception $e) {

            tLog::smallenergy_shop_warning('商家列表展示失败', [
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }

    }

    public static function addSmallEnergy($data, $adminUid)
    {

        try{

            $result = csSmallEnergy::addSmallEnergy($data, $adminUid);

            return $result;

        } catch (\Exception $e) {

            tLog::smallenergy_shop_warning('添加商家客服展示失败', [
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }

    }

    public static function updateSmallEnergy($smallenergyId, $data, $adminUid)
    {

        try{

            $result = csSmallEnergy::updateSmallEnergy($smallenergyId, $data, $adminUid);

            return $result;

        } catch (\Exception $e) {

            tLog::smallenergy_shop_warning('编辑商家客服展示失败', [
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }

    }

    public static function admDelSmallEnergy($smallenergyId)
    {

        try{

            $result = csSmallEnergy::admDelSmallEnergy($smallenergyId);

            return $result;

        } catch (\Exception $e) {

            tLog::smallenergy_shop_warning('删除商家客服信息失败', [
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }

    }

    public static function addMessage($message)
    {
        try{

            $result = csSmallEnergy::addMessage($message);

            return $result;

        } catch (\Exception $e) {

            tLog::smallenergy_shop_warning('推送信息添加失败', [
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }
    }

    public static function setRead($uid, $shopId)
    {
        try{

            $result = csSmallEnergy::setRead($uid, $shopId);

            return $result;

        } catch (\Exception $e) {

            tLog::smallenergy_user_warning('消息修改为已读失败', [
                'uid'   => $uid,
                'shopId' => $shopId,
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }
    }

    public static function getMessageList($uid)
    {
        try{

            $result = csSmallEnergy::getMessageList($uid);

            $array = [
                'list' => $result
            ];

            return $array;

        } catch (\Exception $e) {

            tLog::smallenergy_user_warning('获取消息列表失败', [
                'uid'   => $uid,
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }
    }

    public static function admDelSmallEnergyByShopId($shopId)
    {
        try{

            $result = csSmallEnergy::admDelSmallEnergyByShopId($shopId);

            return $result;

        } catch (\Exception $e) {

            tLog::smallenergy_shop_warning('删除商家客服信息失败', [
                'shop_id' => $shopId,
                'edittime' => date('Y-m-d H:i:s'),
                'e_msg' => $e->getMessage(),
                'e_file' => $e->getFile(),
                'e_line' => $e->getLine()
            ]);

            throw $e;
        }
    }
}